home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / BinaryCodedDecimal.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  2.4 KB  |  68 lines  |  [TEXT/KAHL]

  1. /* BinaryCodedDecimal.h */
  2.  
  3. #ifndef Included_BinaryCodedDecimal_h
  4. #define Included_BinaryCodedDecimal_h
  5.  
  6. /* BinaryCodedDecimal module depends on */
  7. /* MiscInfo.h */
  8. /* Audit */
  9. /* Debug */
  10. /* Definitions */
  11. /* DataMunging */
  12. /* Memory */
  13.  
  14. /* small BCD format is 4 digits of bcd: [+-]xX.XXX, represented as an integer value */
  15. /* that is 1000 (one thousand) times the decimal value (milli-unit precision). */
  16. /* It's range is -29.999 to 29.999 */
  17. typedef short SmallBCDType;
  18. #define SMALLBCDPRECISION (1000)
  19.  
  20. /* small BCD format is 9 digits of bcd: [+-]xXXX.XXXXXX, represented as an integer */
  21. /* value that is 1 000 000 (one million) times the decimal value (micro-unit precision) */
  22. /* It's range is -1999.999999 to 1999.999999 */
  23. typedef long LargeBCDType;
  24. #define LARGEBCDPRECISION (1000000)
  25.  
  26. /* small extended BCD format is 8 digits: [+-]xXXXXXX.XXX, represented as an integer */
  27. /* value that is 1000 (one thousand) times the decimal value. */
  28. /* It's range is -1999999.999 to 1999999.999 */
  29. typedef long SmallExtBCDType;
  30. #define SMALLEXTBCDPRECISION (1000)
  31.  
  32. /* convert small BCD number to double precision floating point number. */
  33. #define SmallBCD2Double(x) ((double)(x) / SMALLBCDPRECISION)
  34. #define SmallBCD2Single(x) ((float)(x) / SMALLBCDPRECISION)
  35.  
  36. /* convert double precision number to small BCD number.  Rounding is towards */
  37. /* nearest. (0.4 ==> 0, 0.6 ==> 1, -0.4 ==> 0, -0.6 ==> -1) */
  38. /* value is constrained if it is out of range */
  39. SmallBCDType            Double2SmallBCD(double Value);
  40.  
  41. /* convert large BCD number to double precision */
  42. #define LargeBCD2Double(x) ((double)(x) / LARGEBCDPRECISION)
  43. #define LargeBCD2Single(x) ((float)(x) / LARGEBCDPRECISION)
  44.  
  45. /* convert double precision number to large BCD number. */
  46. LargeBCDType            Double2LargeBCD(double Value);
  47.  
  48. /* convert small extended BCD number to double precision */
  49. #define SmallExtBCD2Double(x) ((double)(x) / SMALLEXTBCDPRECISION)
  50. #define SmallExtBCD2Single(x) ((float)(x) / SMALLEXTBCDPRECISION)
  51.  
  52. /* convert double precision to small extended BCD number */
  53. SmallExtBCDType        Double2SmallExtBCD(double Value);
  54.  
  55. /* convert small BCD number to string */
  56. char*                            SmallBCDToString(SmallBCDType Number);
  57.  
  58. /* convert large BCD number to string */
  59. char*                            LargeBCDToString(LargeBCDType Number);
  60.  
  61. /* convert small extended BCD number to string */
  62. char*                            SmallExtBCDToString(SmallExtBCDType Number);
  63.  
  64. /* more conversions */
  65. #define SmallExtBCD2LargeBCD(x) ((x) * (LARGEBCDPRECISION / SMALLEXTBCDPRECISION))
  66.  
  67. #endif
  68.